package com.baiytfp.hf.HFDataExchange.common.utils;

import com.baiytfp.hf.baiytfp.common.util.StringUtil;
import com.baiytfp.hf.baiytfp.framework.util.PropertiesUtil;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * 配置通用的基本信息类
 * @author chengy
 *
 */
public class PathInfo {
    
    // 返回 Map 路径数据 (freemarker使用)
    public static Map<String,String> getAppPath(HttpServletRequest request){
    	Map<String,String> m = new HashMap<String,String>();
    	m.put("skinPath", getSkinPath(request));
    	m.put("commonPath", getCommonPath(request));
    	m.put("UIPath", getUIPath(request));
    	m.put("webRoot", getWebRoot(request));
    	m.put("contextPath", request.getContextPath());
        m.put("servicePath", request.getContextPath() + "/service/");
        m.put("viewPath", request.getContextPath()+ "/view/");

        return m;
    }
    
    
    //TODO 需要修改为模板路径第一次判断session里有没有，没有从数据库获取(每个人可能不一样)
    /**
     * freemarker模板路径 ( 加上地区别名 );
     */
    public static String getTemplatePath(HttpServletRequest request){
    	String ftlPath = StringUtil.getString(PropertiesUtil.getString("ftl_templatePath"), "default") + "/";
    	return ftlPath;
    }
    
    /**
     * 取得网页根路径
     * @param request
     * @return
     */
    public static String getWebRoot(HttpServletRequest request){
    	return request.getContextPath() + "/";
    }
    
    /**
     * 取得skin路径
     * @param request
     * @return
     */
    public static String getSkinPath(HttpServletRequest request){
    	return getWebRoot(request) + "skin/" + StringUtil.getString(PropertiesUtil.getString("ftl_skin"), "default") + "/";
    }
    
    /**
     * 取得公用资源目录
     * @param request
     * @return
     */
    public static String getCommonPath(HttpServletRequest request){
        return getWebRoot(request) + "common/";
    }

    
    public static String getUIPath(HttpServletRequest request){
    	String UIPath = "/HFUI/";
        return UIPath;
    }
    
    /**
     * 获取包括协议名://域名:端口号/项目名的根路径
     * @param request
     * @return
     */
    public static String getRealmPath(HttpServletRequest request) {
    	String rootPath = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    	return rootPath;
    }
    
}
